package com.jeejam.storage.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.TreePager;
import com.jeejam.storage.pojo.Depot;
import com.jeejam.storage.sdk.api.IDepotService;
import com.jeejam.storage.sdk.dto.DepotDto;
import com.jeejam.storage.service.DepotService;
import com.jeejam.util.ShopBeanBuildUtil;


import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/18.
 */
@Service(version = "1.0.0")
public class DepotDubboService implements IDepotService {

    @Resource
    private DepotService depotService;

    @Override
    public List<DepotDto> findAll() {
        List<Depot> depotList = depotService.findAll();
        return ShopBeanBuildUtil.slmCopyBeanList(depotList, DepotDto.class);
    }

    @Override
    public List<DepotDto> selectRoot() {
        List<Depot> depotList = depotService.selectRoot();
        return ShopBeanBuildUtil.slmCopyBeanList(depotList, DepotDto.class);
    }

    @Override
    public List<DepotDto> selectRootByPage(int page, int pageSize) {
        List<Depot> depotList = depotService.selectRootByPage(page, pageSize);
        return ShopBeanBuildUtil.slmCopyBeanList(depotList, DepotDto.class);
    }

    @Override
    public List<DepotDto> selectChildren(int id) {
        List<Depot> depotList = depotService.selectChildren(id);
        return ShopBeanBuildUtil.slmCopyBeanList(depotList, DepotDto.class);
    }

    @Override
    public List<DepotDto> selectSubChildren(int parentId) {
        List<Depot> depotList = depotService.selectSubChildren(parentId);
        return ShopBeanBuildUtil.slmCopyBeanList(depotList, DepotDto.class);
    }

    @Override
    public TreePager getTreePager(int currentPage, int pageSize) {
        return depotService.getTreePager(currentPage, pageSize);
    }

    @Override
    public int countsWithRoot() {
        return depotService.countsWithRoot();
    }

    @Override
    public DepotDto findByCode(String code) {
        Depot depot = depotService.findByCode(code);
        return ShopBeanBuildUtil.slmCopyBean(depot, DepotDto.class);
    }

    @Override
    public void deleteWithChildren(int id) {
        depotService.deleteWithChildren(id);
    }

    @Override
    public void save(DepotDto depotDto) {
        depotService.save(ShopBeanBuildUtil.slmCopyBean(depotDto, Depot.class));
    }

    @Override
    public void update(DepotDto depotDto) {
        depotService.update(ShopBeanBuildUtil.slmCopyBean(depotDto, Depot.class));
    }

    @Override
    public DepotDto getById(int id) {
        return ShopBeanBuildUtil.slmCopyBean(depotService.findById(id), DepotDto.class);
    }
}
